<template>
	<view class="wrap">
		<view class="">
			<!-- 2.0.19支持autoBack，默认为false -->
			<u-navbar leftText="密码登录" :autoBack="true">
			</u-navbar>
		</view>
		<view class="top"></view>
		<view class="content">
			<view class="title" style="height: 100rpx;"></view>
			<input class="u-border-bottom" type="number" v-model="tel" placeholder="请输入账号或手机号" />
			<input class="u-border-bottom" type="password" style="margin-top: 30rpx;" v-model="password" placeholder="请输入密码" />
			
			<u-button :customStyle="btnStyle" @click="login">下一步</u-button>
			<view class="alternative">
				<view class="password" @click="cLogin">验证码登录</view>
				<view class="issue">遇到问题</view>
			</view>
		</view>
		<u-toast ref="uToast" />
		<view class="buttom">
			<view class="hint"  style="font-size: 24rpx;">
				登录代表同意
				<text class="link" @click="tolinkfile">龙海智慧物业用户协议、隐私政策，</text>
				并授权使用您的龙海智慧物业账号信息（如昵称、头像、收获地址）以便您统一管理
			</view>
		</view>
	</view>
</template>

<script>
	import { passLogin } from '@/service/loginService.js';
	import cookie from '@/util/store/cookie.js';
	export default {
		data() {
			return {
				tel: '',
				password:'',
				url: '',
				btnStyle: {
					width: '100%',
					height: '80rpx',
					marginTop: '80rpx',
					borderRadius: '60rpx',
					backgroundImage: "url('https://resourse.cnlhjt.com/upload/20220825/d1aa35c1d129137d9b12c8f34e59c5bc.png')",
					backgroundSize: '100% 80rpx',
					fontSize: '34rpx',
					color: '#FFFFFF'
				},
			};
		},
		onLoad() {
			
		},
		methods: {
			login() {
				passLogin({
					username: this.tel,
					password: this.password
				}).then(res=>{
					
					if(res.code == 200){
						var sex = '';
						if(res.result.sex == 1){
							sex = 'man';
						}else{
							sex = 'woman'
						}
						uni.$u.vuex('isLogin', true);
						this.$u.vuex('uid', res.result.id);
						this.$u.vuex('username', res.result.username);
						this.$u.vuex('userid', res.result.userid);
						this.$u.vuex('avatar', res.result.avatar);
						this.$u.vuex('sex', sex);
						this.$u.vuex('level', 0);
						this.$u.vuex('phone', this.tel);
						this.$u.vuex('token', res.result.token);
						uni.$u.vuex('home', res.result.house);
						uni.$u.vuex('userType', res.result.type);
						cookie.set('token', res.result.token);
						cookie.set('uid', res.result.id);
						// webSocket.checkOpenSocket();
						this.error = false;
						this.$u.route({
							url: '/pages/index/index',
							type: 'redirectTo'
						})
					}else{
						this.error = true;
						this.value = '';
						this.$refs.uToast.show({
							message: res.msg,
							type: 'error',
							complete() {
								uni.navigateTo({
									url: '/pages/login/index'
								})
							}
						})
					}
				})
			},
			cLogin(){
				this.$u.route({
					url : '/pages/login/tel-login'
				})
			},
			tolinkfile(){
				this.$u.route({
					url: '/pages/login/linkfile'
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.wrap {
		font-size: 28rpx;
		height: 100%;
		overflow-y: hidden;

		.content {
			width: 600rpx;
			margin: 80rpx auto 0;

			.title {
				text-align: left;
				font-size: 60rpx;
				font-weight: 500;
				margin-bottom: 100rpx;
			}

			input {
				text-align: left;
				margin-bottom: 10rpx;
				padding-bottom: 6rpx;
			}

			.tips {
				color: #666666;
				margin-bottom: 60rpx;
				margin-top: 8rpx;
			}

			.getCaptcha {
				background-color: rgb(253, 243, 208);
				color: #666666;
				border: none;
				font-size: 30rpx;
				padding: 12rpx 0;

				&::after {
					border: none;
				}
			}

			.alternative {
				color: #666666;
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;
			}
		}

		.buttom {
			.loginType {
				display: flex;
				padding: 200rpx 150rpx 150rpx 150rpx;
				justify-content: space-between;

				.item {
					display: flex;
					flex-direction: column;
					align-items: center;
					color: #666666;
					font-size: 28rpx;
				}
			}

			.hint {
				position: fixed;
				bottom: 80rpx;
				padding: 20rpx 40rpx;
				font-size: 20rpx;
				color: #585858;

				.link {
					color: #53C21D;
				}
			}
		}
	}
</style>
